package com.wc.codeforces.线段树.Gifts_Order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/1/4 23:34
 * @description https://codeforces.com/contest/2057/problem/D
 */
public class Main {
    /**
     * 思路：
     * 最大值最小值一定是选择线段的边界
     * 假设左边边界是 最小 a[l], 最大 a[r], 反之同理
     * a[l] < a[r]
     * ans = a[r] - a[l] - (r - l) = (a[r] - r) - (a[l] - l)
     * 证明 a[r] - r > a[l] - l, a[r] > a[l] + r - l > a[l] => a[r] > a[l]
     * 那么我们只需要知道 a[i] - i的右边最大值与左边最小值, 即可算出答案
     * 需要单点修改, 那我们只需要线段树存储即可
     *
     * 反之
     * a[l] > a[r]
     * a[l] - a[r] - (r - l) = (a[l] + l) - (a[r] + r)
     * 证明  a[l] + l > a[r] + r, l <= r, a[l] > a[r]
     * 所以我们同样需要存储 a[i] + i的左边最大值与右边最小值,
     * 比较与上面的哪一个大, 哪一个就是答案
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    // 存储上面的那个
    static int[] maxv1 = new int[N << 2], minv1 = new int[N << 2];
    // 存储下面的那个
    static int[] maxv2 = new int[N << 2], minv2 = new int[N << 2];
    // 存储当前最优解
    static int[] ans1 = new int[N << 2], ans2 = new int[N << 2];

    static int[] a = new int[N];
    static int n, m;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            build(1, 1, n);
            out.println(query());
            while (m-- > 0){
                int x = sc.nextInt(), y = sc.nextInt();
                modify(1, 1, n, x, y);
                out.println(query());
            }
        }
        out.flush();
    }

    static int query() {
        return Math.max(ans1[1], ans2[1]);
    }

    static void modify(int u, int l, int r, int x, int y) {
        if (l == r) {
            maxv1[u] = minv1[u] = y - l;
            maxv2[u] = minv2[u] = y + l;
            ans1[u] = ans2[u] = 0;
            return;
        }
        int mid = l + r >> 1;
        if (x <= mid) modify(u << 1, l, mid, x, y);
        else modify(u << 1 | 1, mid + 1, r, x, y);
        pushUp(u);
    }

    static void build(int u, int l, int r) {
        if (l == r) {
            minv1[u] = maxv1[u] = a[l] - l;
            minv2[u] = maxv2[u] = a[l] + l;
            ans1[u] = ans2[u] = 0;
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static void pushUp(int u) {
        maxv1[u] = Math.max(maxv1[u << 1], maxv1[u << 1 | 1]);
        minv1[u] = Math.min(minv1[u << 1], minv1[u << 1 | 1]);
        maxv2[u] = Math.max(maxv2[u << 1], maxv2[u << 1 | 1]);
        minv2[u] = Math.min(minv2[u << 1], minv2[u << 1 | 1]);

        // (a[r] - r) - (a[l] - l)
        ans1[u] = Math.max(Math.max(ans1[u << 1], ans1[u << 1 | 1]) ,maxv1[u << 1 | 1] - minv1[u << 1]);
        // (a[l] + l) - (a[r] + r)
        ans2[u] = Math.max(Math.max(ans2[u << 1], ans2[u << 1 | 1]), maxv2[u << 1] - minv2[u << 1 | 1]);
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
